package com.happy016.controller;

import com.happy016.feign.UserFeignClient;
import com.happy016.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Feign
 * @author Linyb
 * @since 2017/9/30 15:17
 */
@RestController
@RequestMapping("/consumer/user")
public class UserConsumerController {


    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/get/{id}")
    public User getUser(@PathVariable Integer id){
        //User user = restTemplate.getForObject("http://localhost:8686/user/get/"+id,User.class);
        User user = userFeignClient.findById(id);
        return user;
    }


    @GetMapping("/get")
    public User getUserByIdAndUsername(Integer id,String username){
        User user = userFeignClient.findByIdAndUsername(id,username);
        return user;
    }

    @GetMapping("/get/map")
    public User getUserByMap(Integer id,String username){
        Map<String,Object> params = new HashMap<>();
        params.put("id",id);
        params.put("username",username);
        User user = userFeignClient.findByIdAndUsername(params);
        return user;
    }

    @GetMapping("/post")
    public User getUserByIdAndUsername(User user){
        User ret = userFeignClient.findByPost(user);
        return ret;
    }
}
